package com.ruoyi.project.digital.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.project.digital.domain.TUser;
import com.ruoyi.project.digital.domain.enums.StaminaTypeEnum;
import com.ruoyi.project.digital.service.ITUserService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.digital.mapper.StaminaUserMapper;
import com.ruoyi.project.digital.domain.StaminaUser;
import com.ruoyi.project.digital.service.IStaminaUserService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 体力消耗和获取值Service业务层处理
 *
 * @author ruoyi
 * @date 2023-10-30
 */
@Service
public class StaminaUserServiceImpl extends ServiceImpl<StaminaUserMapper, StaminaUser> implements IStaminaUserService
{

    @Autowired
    private ITUserService userService;

    /**
     * 查询体力消耗和获取值
     *
     * @param id 体力消耗和获取值ID
     * @return 体力消耗和获取值
     */
    @Override
    public StaminaUser selectStaminaUserById(Long id)
    {
        return baseMapper.selectStaminaUserById(id);
    }

    /**
     * 查询体力消耗和获取值列表
     *
     * @param staminaUser 体力消耗和获取值
     * @return 体力消耗和获取值
     */
    @Override
    public List<StaminaUser> selectStaminaUserList(StaminaUser staminaUser)
    {
        return baseMapper.selectStaminaUserList(staminaUser);
    }

    /**
     * 新增体力消耗和获取值
     *
     * @param staminaUser 体力消耗和获取值
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertStaminaUser(StaminaUser staminaUser)
    {
        staminaUser.setType(StaminaTypeEnum.IN.getValue());
        staminaUser.setTitle("系统赠送");
        staminaUser.setCreateTime(DateUtils.getNowDate());
        staminaUser.setTimes(DateUtils.getNowDate());
        TUser tUser=userService.getById(staminaUser.getUserId());
        tUser.setStamina(tUser.getStamina()+staminaUser.getGetValue());
        tUser.setResStamina(tUser.getResStamina()+staminaUser.getGetValue());
        userService.updateById(tUser);
        return baseMapper.insertStaminaUser(staminaUser);
    }

    /**
     * 修改体力消耗和获取值
     *
     * @param staminaUser 体力消耗和获取值
     * @return 结果
     */
    @Override
    public int updateStaminaUser(StaminaUser staminaUser)
    {
        staminaUser.setUpdateTime(DateUtils.getNowDate());
        return baseMapper.updateStaminaUser(staminaUser);
    }

    /**
     * 批量删除体力消耗和获取值
     *
     * @param ids 需要删除的体力消耗和获取值ID
     * @return 结果
     */
    @Override
    public int deleteStaminaUserByIds(Long[] ids)
    {
        return baseMapper.deleteStaminaUserByIds(ids);
    }

    /**
     * 删除体力消耗和获取值信息
     *
     * @param id 体力消耗和获取值ID
     * @return 结果
     */
    @Override
    public int deleteStaminaUserById(Long id)
    {
        return baseMapper.deleteStaminaUserById(id);
    }
}
